package com.chendx.store.order.util;

import com.chendx.model.order.vo.OrderVo;
import com.chendx.model.seckill.vo.SeckillOrderVo;

import java.util.Comparator;

/**
 * Created by chendx on 2022/4/22.
 */
public class ComparatorTime implements Comparator {
    @Override
    public int compare(Object arg0, Object arg1) {

        SeckillOrderVo seckillOrderVo1;
        OrderVo orderVo1;
        SeckillOrderVo seckillOrderVo2;
        OrderVo orderVo2;

        if (arg0 instanceof SeckillOrderVo){
            seckillOrderVo1 = (SeckillOrderVo) arg0;
            if (arg1 instanceof OrderVo){
                orderVo1 = (OrderVo) arg1;
                return seckillOrderVo1.getCreateTime().compareTo(orderVo1.getCreateTime());
            }else {
                seckillOrderVo2 = (SeckillOrderVo) arg1;
                return seckillOrderVo1.getCreateTime().compareTo(seckillOrderVo2.getCreateTime());
            }
        }else{
            orderVo2 = (OrderVo) arg0;
            if (arg1 instanceof OrderVo){
                orderVo1 = (OrderVo) arg1;
                return orderVo2.getCreateTime().compareTo(orderVo1.getCreateTime());
            }else {
                seckillOrderVo1 = (SeckillOrderVo) arg1;
                return orderVo2.getCreateTime().compareTo(seckillOrderVo1.getCreateTime());
            }
        }
    }
}
